package zheezes.eisp.monitor.model;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.TreeMap;

import zheezes.eisp.LocaleResources;
import zheezes.eisp.data.orm.TermPo;
import zheezes.model.ObservableModel;


public class TermVo extends ObservableModel {
	private TermPo model;
	private ResourceBundle resourceBundle;
	private static final Map<String, String> map = new LinkedHashMap<String, String>();

	static {
		map.put("type", LocaleResources.TERM_COLUMN_TYPE);
		map.put("logicAddr", LocaleResources.TERM_COLUMN_ADDR_LOGIC);
		map.put("host", LocaleResources.TERM_COLUMN_HOST);
		map.put("state", LocaleResources.TERM_COLUMN_STATE);
	}

	public TermVo() {
	}

	public TermVo(TermPo model) {
		this.model = model;
	}

	public void setResourceBundle(ResourceBundle resourceBundle) {
		this.resourceBundle = resourceBundle;
	}

	public String getType() {
		switch (model.getType().intValue()) {
		case 0:
			return resourceBundle.getString(LocaleResources.VAR_MASTER);
		case 1:
			return resourceBundle.getString(LocaleResources.VAR_CONCENTRATOR);
		default:
			return resourceBundle.getString(LocaleResources.VAR_UNKNOWN);
		}
	}

	public String getLogicAddr() {
		return model.getLogicAddr();
	}

	public String getHost() {
		return String.format("%s:%d", model.getHost(), model.getPort());
	}

	public String getState() {
		switch (model.getState().intValue()) {
		case 0:
			return resourceBundle.getString(LocaleResources.VAR_OFFLINE);
		case 1:
			return resourceBundle.getString(LocaleResources.VAR_ONLINE);
		default:
			return resourceBundle.getString(LocaleResources.VAR_UNKNOWN);
		}
	}

	public TermPo getModel() {
		return model;
	}

	public void setModel(TermPo model) {
		this.model = model;
	}

	public static final String[] fields() {
		return map.keySet().toArray(new String[0]);
	}

	public static final String[] labels() {
		return map.values().toArray(new String[0]);
	}

	public static final String getLabel(String field) {
		return map.get(field);
	}
}
